package com.ruixin.base.proxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 基础代理类
 */
public class BaseInterceptor implements MethodInterceptor {

    /**
     * 创建Enhancer
     * @param clz
     * @return
     */
    public Enhancer createEnhancer(Class<?> clz){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(clz);
        enhancer.setCallback(this);
        return enhancer;
    }

    /**
     * 拦截器
     * @param proxy
     * @param method
     * @param objects
     * @param methodProxy
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object proxy, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.err.println("================================");
        return methodProxy.invokeSuper(proxy,objects);
    }
}
